/**
 * Author shuqi
 * Rev
 * Date: 2021-07-31 11:15
 * <p>
 * Copyright (C) 2021 Seeyon, Inc. All rights reserved.
 * <p>
 * This software is the proprietary information of Seeyon, Inc.
 * Use is subject to license terms.
 * @company seeyon.com
 * @author shuqi
 * @since V5 V7.1
 */
package com.synnex.springboot.config;

import org.springframework.context.ApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

/**
 * @description
 * @date 2021-07-31 11:15
 * @author xiaol
 */
public class MyWebApplicationInitializer implements WebApplicationInitializer {

	private static ApplicationContext applicationContext;

	@Override
	public void onStartup(ServletContext servletContext) {
		ServletRegistration dispatcherServlet = servletContext.getServletRegistration("myDispatcherServlet");
		if (dispatcherServlet == null) {
			DispatcherServlet myDispatcherServlet = (DispatcherServlet) applicationContext.getBean("myDispatcherServlet");
			ServletRegistration.Dynamic dispatcherServlet1 = servletContext.addServlet("myDispatcherServlet", myDispatcherServlet);
			dispatcherServlet1.setLoadOnStartup(1);
			dispatcherServlet1.addMapping("/");
		}

	}

	public static void setApplicationContext(ApplicationContext applicationContext) {
		MyWebApplicationInitializer.applicationContext = applicationContext;
	}
}
